const Address=require('../model/addr.model')
const Cart = require("../model/cart.model");
class AddrServer{
    async createAddress(addr){
        return Address.create(addr);
    }
    async getAddrListOpera(user_id){
        return await Address.findAll({
            where:{user_id},
            attributes:['user_id','address','telephone','buyPeople','selected','id']

        })
    }
    async updateAddress(user_id,id,params){
        if (params.selected===true){
            await Address.update({selected:false},{where:{
                    user_id:user_id
                }})
        }
        const res=await Address.update(params,{where:{
                user_id:user_id,id:id
            }})
        return res

    }
    async removeAddress(user_id,id){
        const res=await Address.destroy({
            where:{
                user_id,id
            }
        })
        return res
    }
}
module.exports=new AddrServer()